var ajks = function(){
	var xmlhttp;
	if (window.XMLHttpRequest){
		//  IE7+, Firefox, Chrome, Opera, Safari 浏览器执行代码
		xmlhttp=new XMLHttpRequest();
	}
	else{
		// IE6, IE5 浏览器执行代码
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	xmlhttp.onreadystatechange=function(){
		if (xmlhttp.readyState==4 && xmlhttp.status==200)
		{
			// 开始自己写
			var json = JSON.parse(xmlhttp.responseText);
			var imgs=1;
			for(var i = 0;i<json.sites.length;i++){
				document.querySelector('.good_1').innerHTML+='<li><a href=""><div class="img left"><img src="images/commodity/commodity_'+N+'/'+imgs+'.webp" alt=""></div><div class="txt_3 left"><h4>'+json.sites[i].txt_1+'</h4><p>'+json.sites[i].txt_2+'</p><div class="progress_bar"><div class="progress_bar_" style="width: '+json.sites[i].sell_out/json.sites[i].have*100+'%;"></div></div><p class="progress_bar_specific"><span class="percentage">'+Math.round(json.sites[i].sell_out/json.sites[i].have*100)+'%</span><span class="sell_out">已抢'+json.sites[i].sell_out+'件</span></p><h3><span class="h3_1">￥</span><span class="h3_2">'+json.sites[i].txt_3+'</span><span class="h3_3">'+json.sites[i].txt_4+'</span></h3></div></a></li>';
				// '+json.sites[i].txt_1+'
				imgs++;
			}
			N++;
			if (N >= json.sites.length+1) {N=1}
			// 结束自己写
		}
	}
	xmlhttp.open("GET","json/text"+N+".json",true);
	// 盘好路径
	xmlhttp.send();
}
var N = 1;
ajks();
document.querySelector('#change').onclick=function(){
	document.querySelector('.good_1').innerHTML='';
	ajks();
}



// 倒计时
var countdown = function(){
	var n_time = new Date('2019-09-18 10:00').getTime();
	var o_time = new Date().getTime();
	var ms = parseInt((n_time-o_time)/1000);
	var h = parseInt(ms/3600);
	var m = parseInt(ms/60)%60;
	var s = parseInt(ms%60);
	h = h<10 ? '0'+h : h;
	m = m<10 ? '0'+m : m;
	s = s<10 ? '0'+s : s;
	if (ms<=0) {
		clearInterval(count_time);
		time_p.innerHTML='秒杀结束';
	}else{
		time_h.innerHTML = h;
		time_m.innerHTML = m;
		time_s.innerHTML = s;
	}
}
var count_time = setInterval(countdown,1000);
countdown();